﻿using System;
using System.Web;
using System.Web.UI.WebControls;

namespace NazTek.Extension.Clr4
{
    /// <summary>
    /// Extends <see cref="System.Web.UI.WebControls.Label"/>.
    /// </summary>
    public static class LabelExtension
    {
        /// <summary>
        /// Sets the Text proprey value.
        /// </summary>
        /// <typeparam name="T">Data type of the value</typeparam>
        /// <param name="label">The <see cref="System.Web.UI.WebControls.Label"/> instance whose Text value is to be set.</param>
        /// <param name="value">The value to format and set.</param>
        /// <param name="formatter">Used for non-string types to make culture neutral.</param>
        public static void SetText<T>(this Label label, T value, FormatOption formatter = FormatOption.Base64Soap) where T : IComparable
        {
            if (typeof(T) == typeof(string))
                HttpUtility.HtmlEncode(value as string);
            else
                label.Text = value.ToString(formatter);
        }
    }
}